<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>计算属性和观察者</title>
    <!--通过如下方式引入 Vue-->
    <script src="https://unpkg.com/vue"></script>
</head>
<body>
    <div id="example">
        <p>Original message: "{{ message }}"</p>
        <p>Computed reversed message: "{{ reversedMessage }}"</p>
        <p>Reversed message: "{{ reversedMessageFn() }}"</p>
        <p>Computed now: "{{ now }}"</p>
    </div>
    <div id="demo">
        {{fullName}}
    </div>
</body>
<script type="text/javascript">
    var vm = new Vue({
        el:'#example',
        data:{
            message:'Hello'
        },
        /**
         * 计算属性
         */
        computed: {
            // a computed getter
            reversedMessage: function () {
                // `this` points to the vm instance
                return this.message.split('').reverse().join('');
            },
            now: function () {
                return new Date().toLocaleString();
            }
        },
        methods:{
            reversedMessageFn:function () {
                return this.message.split('').reverse().join('');
            }
        }
    });

    var demo = new Vue({
        el:'#demo',
        data:{
            firstName:'孤傲',
            lastName:'苍狼'
        },
        computed:{
            fullName:function () {
                return this.firstName+this.lastName
            }
        }
    });
</script>
</html>
